package com.aldobucchi.utils
{
	
	
	import flash.utils.Dictionary;
	
	import com.aldobucchi.core.markers.IValueSingleton;
	
	
	
	/**
	 * 
	 * a labeled directed arc... used in several parts ( rdf, facets, evals, etc )
	 * 
	 * @author aldo.bucchi@gmail.com
	 * 
	 */	
	public class Arc implements IValueSingleton
	{
		
		
		private var _label:*;
		
		public function get label( ):*
		{
			return _label;
		}
		
		
		private var _inverted:Boolean;
		
		public function get inverted( ):Boolean
		{
			return _inverted;
		}
		
		
		public function Arc( label:*, inverted:Boolean=false )
		{
			
			_label = label;
			_inverted = inverted;
			
		}


		
		
		
		
		
		
		public function toString( ):String
		{
		
			return "Arc( " + label + ( inverted ? " -inv" : "" ) + " )";		
		
		}
		
		
		
		
		
		///////////////////////////////////////
		//
		///////////////////////////////////////

		
		private static var cache			:Dictionary = new Dictionary( true );
		private static var invertedCache	:Dictionary = new Dictionary( true );
		
		
		public static function instance( label:*, inverted:Boolean=false ):Arc
		{
		
			var c:Dictionary = inverted ? invertedCache : cache;
				
			if ( ! (c[ label ] is Arc) )
			{
				c[ label ] = new Arc( label, inverted );			
			}
		
			return c[ label ] as Arc;
		
		}
		
		

	}
	

}


